package me.zhengjie.modules.logistics.rest;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.zhengjie.annotation.Log;
import me.zhengjie.modules.logistics.domain.req.LogisticsOrderCommitReq;
import me.zhengjie.modules.logistics.domain.req.LogisticsOrderReq;
import me.zhengjie.modules.logistics.domain.resp.LogisticsOrderResp;
import me.zhengjie.modules.logistics.service.LogisticsOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@Api(tags = "物流")
@Slf4j
@RequestMapping("/api/logistics")
public class LogisticsOrderController {


    private final LogisticsOrderService logisticsOrderService;

    @PostMapping("/qry")
    @Log("查询购买商品的订单信息-快递100")
    @ApiOperation("查询购买商品的订单信息-快递100")
    public ResponseEntity<LogisticsOrderResp> queryOrder(@RequestBody LogisticsOrderReq req) throws Exception {
        return new ResponseEntity<>(logisticsOrderService.queryOrder(req),HttpStatus.OK);
    }

    @PostMapping("/submit")
    @Log("提交物流订单")
    @ApiOperation("提交物流订单")
    public ResponseEntity<Object> submitOrder(@RequestBody LogisticsOrderCommitReq req) throws Exception {
        logisticsOrderService.submitOrder(req);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @PostMapping("/cancel")
    @Log("取消物流订单")
    @ApiOperation("取消物流订单")
    public ResponseEntity<Object> cancelOrder(@RequestBody LogisticsOrderReq req) throws Exception {
        logisticsOrderService.cancelOrder(req);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @PostMapping("/callBack")
    @Log("订单回调")
    @ApiOperation("订单回调")
    public ResponseEntity<Object> callBack(){
        log.info("回调成功");
        return new ResponseEntity<>(HttpStatus.OK);
    }
}
